package com.wanxi.education.controller.front;

import com.wanxi.education.common.CommonResult;
import com.wanxi.education.model.vo.advertandcertificate.CertificateAddVo;
import com.wanxi.education.model.vo.advertandcertificate.CertificateFrontVo;
import com.wanxi.education.service.CertificateService;
import com.wanxi.education.service.CourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * @Author: yanguangqiong
 * @Description:
 * @Date: Created in 2021/9/24
 * @Version: 1.0
 */
@Api(tags = "前端证书")
@RestController
@RequestMapping("/user/front/certificate")
public class CertificateFrontController {
    @Autowired
    private CertificateService certificateService;
    @Autowired
    private CourseService courseService;
    @GetMapping("/findById")
    @ApiOperation("查看证书详情信息")
    public CommonResult<CertificateFrontVo> findByIdForFront(@RequestParam("courseId") Long courseId) {
        CertificateFrontVo certificateFrontVo = certificateService.findByIdForFront(courseId);
        Integer count = courseService.findCourseCountById(courseId);
        certificateFrontVo.setCourseDuration(count);
        BigDecimal price = courseService.findCoursePriceById(courseId);
        certificateFrontVo.setPrice(price);
        Integer sale=courseService.findCourseSaleById(courseId);
        certificateFrontVo.setSale(sale);
        return CommonResult.success(certificateFrontVo);
    }
}
